

package com.master.train.member.controller;

import com.master.train.common.utils.PageUtils;
import com.master.train.common.utils.R;
import com.master.train.member.entity.MemberEntity;
import com.master.train.member.req.MemberLoginReq;
import com.master.train.member.resp.MemberLoginResp;
import com.master.train.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 会员
 *
 * @author master
 * @email 3221057417@qq.com
 * @date 2025-07-02 18:01:07
 */
@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("member:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("member:member:info")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    @RequestMapping("/send-code")
//    @RequiresPermissions("member:member:save")
    public R sendCode(@RequestBody @Valid MemberEntity member){
        memberService.sengCode(member);

        return R.ok();
    }

    @RequestMapping("/login")
//    @RequiresPermissions("member:member:save")
    public R login(@RequestBody @Valid MemberLoginReq loginReq){
        MemberLoginResp login = memberService.login(loginReq);
        System.out.println(login);
        return R.ok().put("member", login);
    }
    @GetMapping("/count")
    public R gatCount(){
        long count = memberService.count();
        return R.ok().put("count", count);
    }



    /**
     * 保存
     */

    @RequestMapping("/save")
//    @RequiresPermissions("member:member:save")
    public R save(@RequestBody @Valid MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("member:member:update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("member:member:delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("/test")
    public R test(){
        return R.ok().put("msg", "测试");
    }

}